www.gusucode.com > LTE基带收发仿真系统matlab源码程序 > LTE baseband simulation/logmapo.m

    function L_all = logmapo(rec_s,g,L_a,ind_dec)
% 函数实现的主要功能:对解调信号进行Log-Map译码,计算LLR
% 输入变量: 
%     rec_s: 接受比特的加权. 
%     rec_s = 0.5 * L_c * yk = ( 2 * a * rate * Eb/N0 ) * yk
%     g: 生成矩阵.
%     L_a: 另一个分量译码器的先验信息
%     ind_dec: 分量译码器的索引号 
% 输出变量: 
%     L_all: 概率对数似然比值.
%  Author:		程式小组(徐萌 张妙 张晓庆)
%  Date:		2010-07-11
%  ==========================================================


% Total number of bits: Inftyo. + tail
L_total = length(rec_s)/2;
[n,K] = size(g); 
m = K - 1;
nstates = 2^m;          % number of states in the trellis

% Set up the trellis
[next_out, next_state, last_out, last_state] = trellis(g);

Infty = 1e10;

% Initialization of Alpha
Alpha(1,1) = 0; 
Alpha(1,2:nstates) = -Infty*ones(1,nstates-1);

% Initialization of Beta
if ind_dec==1
   Beta(L_total,1) = 0;
   Beta(L_total,2:nstates) = -Infty*ones(1,nstates-1); 
elseif ind_dec==2
   Beta(L_total,1:nstates) = zeros(1,nstates);
else
   fprintf('ind_dec is limited to 1 and 2!\n');
end

% Trace forward, compute Alpha
tempmax = zeros(1,L_total+1);
for k = 2:L_total+1
    for state2 = 1:nstates
      gamma = -Infty*ones(1,nstates);
      gamma(last_state(state2,1)) = (-rec_s(2*k-3)+rec_s(2*k-2)*last_out(state2,2))....
           -log(1+exp(L_a(k-1)));
      gamma(last_state(state2,2)) = (rec_s(2*k-3)+rec_s(2*k-2)*last_out(state2,4))....
           +L_a(k-1)-log(1+exp(L_a(k-1)));

      if(sum(exp(gamma+Alpha(k-1,:)))<1e-300)
         Alpha(k,state2)=-Infty;
      else
         Alpha(k,state2) = log( sum( exp( gamma+Alpha(k-1,:) ) ) );  
      end   
    end
    tempmax(k) = max(Alpha(k,:));
    Alpha(k,:) = Alpha(k,:) - tempmax(k);
end     

% Trace backward, compute Beta
for k = L_total-1:-1:1
  for state1 = 1:nstates
     gamma = -Infty*ones(1,nstates);
     gamma(next_state(state1,1)) = (-rec_s(2*k+1)+rec_s(2*k+2)*next_out(state1,2))....
           -log(1+exp(L_a(k+1)));
     gamma(next_state(state1,2)) = (rec_s(2*k+1)+rec_s(2*k+2)*next_out(state1,4))....
           +L_a(k+1)-log(1+exp(L_a(k+1)));
     if(sum(exp(gamma+Beta(k+1,:)))<1e-300)
        Beta(k,state1)=-Infty;
     else
        Beta(k,state1) = log(sum(exp(gamma+Beta(k+1,:))));
     end   
  end
  Beta(k,:) = Beta(k,:) - tempmax(k+1);
end

% Compute the soft output, log-likelihood ratio of symbols in the frame
L_all=zeros(1,L_total);
temp0=zeros(1,nstates);
temp1=zeros(1,nstates);
for k = 1:L_total
  for state2 = 1:nstates
     gamma0 = (-rec_s(2*k-1)+rec_s(2*k)*last_out(state2,2))....
           -log(1+exp(L_a(k)));
     gamma1 = (rec_s(2*k-1)+rec_s(2*k)*last_out(state2,4))...
           +L_a(k)-log(1+exp(L_a(k)));
     temp0(state2) = exp(gamma0 + Alpha(k,last_state(state2,1)) + Beta(k,state2));
     temp1(state2) = exp(gamma1 + Alpha(k,last_state(state2,2)) + Beta(k,state2));
  end
  L_all(k) = log(sum(temp1)) - log(sum(temp0));
end